<?php
// +----------------------------------------------------------------------
// | Bwsaas
// +----------------------------------------------------------------------
// | Copyright (c) 2015~2020 http://www.buwangyun.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Gitee ( https://gitee.com/buwangyun/bwsaas )
// +----------------------------------------------------------------------
// | Author: buwangyun <hnlg666@163.com>
// +----------------------------------------------------------------------
// | Date: 2020-9-28 10:55:00
// +----------------------------------------------------------------------

namespace app\common\model;

use buwang\base\BaseModel;

class MemberMiniappOrder extends BaseModel
{

    protected $pk = 'id';

    // 追加属性
    protected $append = [
        'createtime_text',
        'expiretime_text'
    ];

    public function getCreatetimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['create_time']) ? $data['create_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getExpiretimeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['expire_time']) ? $data['expire_time'] : '');
        return is_numeric($value) ? date("Y-m-d H:i:s", $value) : $value;
    }

    public function getPriceInfoAttr($value, $data) {
        $value = $value ? : (isset($data['miniapp_module_price_json']) ? $data['miniapp_module_price_json'] : '');
        if (empty($value)) {
            return [];
        }
        $dec = json_decode($data['miniapp_module_price_json'], TRUE);
        if (empty($dec)) {
            return [];
        }

        return $dec;
    }
}